#include "Channel.h"

namespace
{
	int clientId = 0;
}

Channel::Channel()
{
	clientId++;
}

Channel::~Channel()
{
}

ACE_HANDLE Channel::get_handle() const
{
	return this->m_socketStream.get_handle();
}


int Channel::handle_input(ACE_HANDLE fd)
{
	ACE_Time_Value nowait (ACE_Time_Value::zero);
	char buff[1024] = {0};
	int recvbyte = m_socketStream.recv(buff, 1024, &nowait);
	if(recvbyte > 0)
	{
		printf("Recieved [key %d] [data %s]\n",clientId, buff);
	}
	else
	{
		printf("Client will closed [handler:%d] ", fd);
		// return -1 to triggered handle_close()
		return -1;
	}
	return 0;
}

int Channel::handle_close(ACE_HANDLE handle, ACE_Reactor_Mask close_mask)
{
	printf("Client closed [handler:%d]\n", handle);
	return 0;
}